package com.gin.no_gay_alliance.adpter.follow;

import android.content.Context;
import android.text.Html;
import android.text.method.LinkMovementMethod;

import androidx.annotation.NonNull;

import com.gin.common.utils.TimeUtils;
import com.gin.nga.bbscode.entity.BbsTag;
import com.gin.nga.bbscode.utils.BbsTagParser;
import com.gin.nga.enums.FollowStatusType;
import com.gin.nga.response.field.FollowStatus;
import com.gin.no_gay_alliance.adpter.base.BaseBindingRecyclerViewAdapter;
import com.gin.no_gay_alliance.databinding.ItemFollowDynamicsBinding;
import com.gin.no_gay_alliance.utils.BbsCodeUtils;

import java.util.List;

/**
 * 关注动态适配器
 *
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/9/13 20:27
 **/
public class DynamicsAdapter extends BaseBindingRecyclerViewAdapter<ItemFollowDynamicsBinding, FollowStatus> {
    public DynamicsAdapter(Context context) {
        super(context);
    }

    public DynamicsAdapter(@NonNull Context context, @NonNull List<FollowStatus> data) {
        super(context, data);
    }

    /**
     * 绑定数据
     *
     * @param holder
     * @param b        绑定对象
     * @param position 位置
     * @param item
     */
    @Override
    protected void onBindViewHolder(ViewHolder<ItemFollowDynamicsBinding> holder, @NonNull ItemFollowDynamicsBinding b, int position, FollowStatus item) {
        List<BbsTag> bbsTags = BbsTagParser.parseContent(item.getSummary());
        String content = BbsCodeUtils.toHtml4TextView(bbsTags);

        b.tvType.setText(getTypeName(item.getType()));
        b.tvTimestamp.setText(TimeUtils.format(item.getTimestamp(), TimeUtils.SHORT_FORMATTER));
        b.tvContent.setText(Html.fromHtml(content, Html.FROM_HTML_MODE_COMPACT));
        b.tvContent.setMovementMethod(LinkMovementMethod.getInstance());
    }

    private static String getTypeName(FollowStatusType type) {
        switch (type) {
            case TOPIC:
                return "[发布主题]";
            case REPLY:
                return "[发布回复]";
            case FAV:
                return "[收藏主题]";
            default:
                return "[未知类型]";
        }
    }
}
